import requests
import random
from DataTest.ANR.path import *
from DataTest.JsonData.read_json import load_json

self_token, match_token = load_json(json_data_path)
meeting_list = ['meeting_summer', 'meeting_school']
type_list = [1, 2]
two_meeting = []
one_meeting = []


def application():
    """
    报名奇遇：夏日奇遇：meeting_summer，上学奇遇：meeting_school
    :return:self_token 报名奇遇
    """
    application_type = random.choice(type_list)

    for token in self_token:

        header = {
            'Authorization': f'Bearer {token}',
            'Content-Type': 'application/json',
        }

        if application_type == 1:

            meeting_type = random.choice(meeting_list)

            application_url = f'http://124.220.33.63:8700/api/v2/meetings/{meeting_type}/signup'
            res = requests.post(url=application_url, headers=header)

            if res.status_code == 200:
                one_meeting.append(token)
                print(f'用户{token}报名奇遇{meeting_type}成功')

            else:
                print(f'用户{token}报名奇遇{meeting_type}失败')

        if application_type == 2:

            for meeting_type in meeting_list:

                application_url = f'http://124.220.33.63:8700/api/v2/meetings/{meeting_type}/signup'
                res = requests.post(url=application_url, headers=header)

                if res.status_code == 200:
                    two_meeting.append(token)
                    print(f'用户{token}报名奇遇{meeting_type}成功')

                else:
                    print(f'用户{token}报名奇遇失败或已报名')

    print(f'报名一个奇遇的用户有{one_meeting}，人数为{len(one_meeting)}')
    print(f'报名两个奇遇的用户有{two_meeting}，人数为{len(two_meeting)}')


if __name__ == '__main__':
    application()
